#include "node.h"


std::ostream& operator<< (std::ostream&  s, const Node & n) {
    s << "(" << n.row << "," << n.col << ")";//<< "|" << n.g << "," << n.h << ")";
    return s;
}


Node::Node(const Node &n) {
    g = n.g;
    h = n.h;
    col = n.col;
    row = n.row;
    parent = n.parent;
    std::map<pair,NodeGraphics*,pairLess>::iterator i = NodeGraphics::NodesMap.find(pair(row,col));
    if(i == NodeGraphics::NodesMap.end())
        graph = NULL;
    else
        graph = NodeGraphics::NodesMap[pair(row,col)];
}

Node::Node(int row_, int col_)
{
    g = 0;
    h = 0;
    col = col_;
    row = row_;
    std::map<pair,NodeGraphics*,pairLess>::iterator i = NodeGraphics::NodesMap.find(pair(row,col));
    if(i == NodeGraphics::NodesMap.end())
        graph = NULL;
    else
        graph = NodeGraphics::NodesMap[pair(row,col)];
    parent = NULL;
}

Node::Node() {
    g = -1;
    h = -1;
    row = -1;
    col = -1;
    std::map<pair,NodeGraphics*,pairLess>::iterator i = NodeGraphics::NodesMap.find(pair(row,col));
    if(i == NodeGraphics::NodesMap.end())
        graph = NULL;
    else
        graph = NodeGraphics::NodesMap[pair(row,col)];
    parent = NULL;
}

Node::Node(int row_, int col_,Node *parent_) {
    parent = parent_;
    g = 0;
    h = 0;
    col = col_;
    row = row_;
    std::map<pair,NodeGraphics*,pairLess>::iterator i = NodeGraphics::NodesMap.find(pair(row,col));
    if(i == NodeGraphics::NodesMap.end())
        graph = NULL;
    else
        graph = NodeGraphics::NodesMap[pair(row,col)];
}

bool Node::operator<(const Node &b) const{
    double tmp = (g + h) - (b.g + b.h);
    if (tmp < 0){
        return true;
    }
    return false;
}

Node & Node::operator=(const Node &b) {
    g = b.g;
    h = b.h;
    col = b.col;
    row = b.row;
    parent = b.parent;
    return (*this);
}

double Node::getCost() {
    return g+h;
}


bool Node::operator==(const Node &b) const {
    if(col == b.col && row == b.row)
        return true;
    return false;
}

